import { _decorator, Canvas, CCBoolean, CCString, Component, ConfigurableConstraint, Node, ResolutionPolicy, screen, Sprite, UITransform, view } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('CanvasResize')
export class CanvasResize extends Component {
  @property(UITransform)
  spr: UITransform;
  @property(CCBoolean)
  isLeft: boolean = false;
  protected start(): void {
    const viewSize = view.getVisibleSize();
    // console.log(viewSize);
    const fixSize = {
      width: 720,
      height: 1334,
    };
    const targetSize = {
      width: (fixSize.width / fixSize.height) * viewSize.height,
      height: viewSize.height,
    };
    if (this.isLeft) {
      this.node.setPosition(viewSize.width > targetSize.width ? -targetSize.width / 2 : -viewSize.width / 2, 0);
    } else {
      this.node.setPosition(viewSize.width > targetSize.width ? targetSize.width / 2 : viewSize.width / 2, 0);
    }
    this.spr.width = 2000;
  }
}
